<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class PassController extends Controller
{
	//密码修改首页
    public function getIndex()
    {
        //解析页面
        return view('system/password/pass');

    } 
    //执行修改密码
    public function postUpdate(Request $request)
    {
    	$id = session('id');
    	// dd($info);
    	//验证密码
        if($id){
            $res = $request->all();
            $info = DB::table('person')->where('id',$id)->get();
        

        	if (Hash::check($res['password'], $info[0]['PassWord'])) {
    		   $this->validate($request, [
    		        'PassWord' => 'required',
    		        'repassword' => 'required|same:PassWord',
        		],[
        			'PassWord.required'=>'密码不能为空',
        			'repassword.required'=>'重复密码不能为空',
        			'repassword.same'=>'两次密码不一致',
        		]);
    		   // $res = $request['Password'];
    		   // dd($res);
    		   $newpass['PassWord'] = Hash::make($res['PassWord']);
    		   // dd($newpass);
    		   DB::table('person')->where('id',$id)->update($newpass);
    		   return redirect('/login')->with('error','请重新登录');
    		}
    	   return back()->with('error','密码错误');
        }
        return redirect('/login')->with('error','您还没有登录,请先登录');

    }

}
